#include "GameOpt.h"
//#include "Point.h"


Point::Point(const int x, const int y) 
{
	(*this)(x,y);
}

Point::Point(const Point & pnt)
{
	(*this)(pnt.x(),pnt.y());
}

//Set Point
Point & Point::operator()(int x,int y)
{
	xPos = x;
	yPos = y;
	return *this;
}

Point & Point::operator()(Point & pnt)
{
	xPos = pnt.xPos;
	yPos = pnt.yPos;
	return *this;
}

// Extractors.
int Point::x() const
{ 
	return xPos;
}
int Point::y() const
{ 
	return yPos; 
}

int Point::getQuadrate() const
// returns the quadrate of the point, or the exact angle incase between quadrates
{
	if (xPos > 0 && yPos < 0)				// first quadrate
		return 1;
	else
		if (xPos < 0 && yPos < 0)			// second quadrate
			return 2;
		else
			if (xPos < 0 && yPos > 0)		// third quadrate
				return 3;
			else
				if (xPos > 0 && yPos > 0)	// fourth quadrate
					return 4;

	//  edge cases incase between quadrates
	if (xPos==0)
		if(yPos==0)
			return 0;
		else
			if (yPos<0)
				return 90;
			else
				if (yPos>0)
					return 270;

	if (yPos==0)
		if (xPos>0)
			return 0;
		else
			if (xPos<0)
				return 180;
// end of edge cases
	return -1;
}

// Distance to another point.  Pythagorean thm.
double Point::dist(const Point & other) const
{
	double xd = xPos - other.xPos;
	double yd = yPos - other.yPos;
	return sqrt(pow(xd,2) + pow(yd,2));
}

double Point::angle(const int x,const int y) const
{
	return angle(Point(x,y));
}
double Point::angle(Point other) const
{
	Point diff=other-(*this);
	double ang;
	double x=diff.x();
	double y=diff.y();
	int	Quadrate=diff.getQuadrate();

	if (Quadrate>=1 && Quadrate<=4)
	{
		ang=atan(abs(y/x)) * 180 / PI;

		switch (Quadrate)
		{
		case 1:
			break;
		case 2:
			ang=180-ang;
			break;
		case 3:
			ang+=180;
			break;
		case 4:
			ang=360-ang;
			break;
		default:
			cout<< "Between Quadrates, already taken care of" << endl;
			break;
		}
	}
	else
		ang=Quadrate; // in between Quadrates
	return ang;
}
        // Add or subtract two points.
Point Point::operator+(const Point & b)
{
	return Point(xPos + b.xPos, yPos + b.yPos);
}

Point Point::operator-(const Point & b)
{
	return Point(xPos - b.xPos, yPos - b.yPos);
}

bool Point::operator==(const Point & b)
{
	return ((xPos==b.x()) && (yPos==b.y()));
}
double Point::operator%(const Point &b)
{
	return dist(b);
}
// Move the existing point.
Point & Point::add(int a, int b)
{
	xPos += a;
	yPos += b;
	return (*this);
}
